package com.six.firstpage.controller.api;

import com.six.core.entity.Collection;
import com.six.core.vo.Result;
import com.six.firstpage.service.CollectionService;
import com.six.firstpage.vo.dto.CollectionGoodsDto;
import com.six.firstpage.vo.dto.CollectionShopDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author:zzh
 * @create: 2023-03-04 10:29
 * @Description:
 */
@Api(value = "firstpage/api/collection", tags = {":"})
@RestController
@RequestMapping("firstpage/api/collection")
public class ApiCollectionController {

    @Autowired
    private CollectionService collectionService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "goodsid", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "shopid", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/getCollection/{goodsid}/{shopid}")
    public Result getCollection(@PathVariable Integer goodsid,@PathVariable Integer shopid){
        Map<String, List<Collection>> collection = collectionService.getCollection(goodsid, shopid);
        return new Result(2000,"查询用户收藏信息成功",collection);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Collection", name = "collection", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addCollection")
    public Result addCollection(@RequestBody Collection collection){
        Integer integer = collectionService.addCollection(collection);
        if (integer>0){
            return new Result(2000,"收藏成功");
        }
        return new Result(5000,"收藏失败");
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delCollection/{id}")
    public Result delCollection(@PathVariable Integer id){
        Integer integer = collectionService.delCollection(id);
        if (integer>0){
            return new Result(2000,"取消收藏成功");
        }
        return new Result(5000,"取消收藏失败");
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getCollectionShop")
    public Result getCollectionShop(){
        List<CollectionShopDto> collections = collectionService.allCollectionShop();
        return new Result(2000,"查询收藏店铺信息成功",collections);
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getCollectionGoods")
    public Result getCollectionGoods(){
        List<CollectionGoodsDto> collections = collectionService.allCollectionGoods();
        return new Result(2000,"查询收藏商品信息成功",collections);
    }



}
